package com.medicine.controller.user;

import com.medicine.constant.StatusConstant;
import com.medicine.entity.Group;
import com.medicine.result.Result;
import com.medicine.service.GroupService;
import com.medicine.vo.MedicineItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "C端-药组浏览接口")
public class GroupController {
    @Autowired
    private GroupService groupService;

    /**
     * 条件查询
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询药组")
    @Cacheable(cacheNames = "groupCache",key = "#categoryId") //key: groupCache::100
    public Result<List<Group>> list(Long categoryId) {
        Group group = new Group();
        group.setCategoryId(categoryId);
        group.setStatus(StatusConstant.ENABLE);

        List<Group> list = groupService.list(group);
        return Result.success(list);
    }

    /**
     * 根据药组id查询包含的药品列表
     *
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("根据药组id查询包含的药品列表")
    public Result<List<MedicineItemVO>> dishList(@PathVariable("id") Long id) {
        List<MedicineItemVO> list = groupService.getMedicineItemById(id);
        return Result.success(list);
    }
}
